package com.rritw.webtools.action.tool;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.util.HtmlUtils;

import com.rritw.webtools.action.IpsAction;
import com.rritw.webtools.util.JSoapUtil;
import com.rritw.webtools.util.StringUtil;

@Controller
@Scope("prototype")
public class JsonValidatorAction extends IpsAction {

    private static final long   serialVersionUID = 7002985971708790168L;
    private static final Logger log              = Logger.getLogger(JsonValidatorAction.class);
    private String              htmlContent;

    private String              htmlContentResult;

    public String index() {
        super.init();
        return SUCCESS;
    }

    public String create() {
        try {
            super.init();
            htmlContentResult = JSoapUtil.formatHtml(htmlContent);
            if (!StringUtil.isEmpty(htmlContent)) {
                htmlContent = HtmlUtils.htmlEscape(htmlContent);
            }
            if (!StringUtil.isEmpty(htmlContentResult)) {
                htmlContentResult = HtmlUtils.htmlEscape(htmlContentResult);
            }
        } catch (Exception e) {
            log.error("Format html exception happened:" + e.getMessage(), e);
        }
        return SUCCESS;
    }

    public String getHtmlContent() {
        return htmlContent;
    }

    public String getHtmlContentResult() {
        return htmlContentResult;
    }

    public void setHtmlContent(String htmlContent) {
        this.htmlContent = htmlContent;
    }

}
